package com.spotmanger.project.modular.spottable.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spotmanger.project.common.core.utils.DataResult;
import com.spotmanger.project.modular.spottable.entity.SpottableHistoricalmineNewEntity;
import com.spotmanger.project.modular.spottable.service.SpottableHistoricalmineNewService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;



/**
 * 历史遗留图斑的信息表，所有历史遗留图斑录入均需要填写该表。
 *
 * @author leihao
 * @email 1321451088@qq.com
 * @date 2021-09-20 10:53:23
 */
@Controller
@RequestMapping("/")
public class SpottableHistoricalmineNewController {
    @Resource
    private SpottableHistoricalmineNewService SpottableHistoricalmineNewService;


    /**
     * 跳转到页面
     */
    @GetMapping("/index/historicalmine")
    public String historicalmine() {
        return "spottable/spottablehistoricalminenew/list";
    }

    @ApiOperation(value = "新增")
    @PostMapping("historicalmine/add")
    @RequiresPermissions("historicalmine:add")
    @ResponseBody
    public DataResult add(@RequestBody SpottableHistoricalmineNewEntity spottableHistoricalmine) {
        SpottableHistoricalmineNewService.save(spottableHistoricalmine);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("historicalmine/delete")
    @RequiresPermissions("historicalmine:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> TBBHs) {
        SpottableHistoricalmineNewService.removeByIds(TBBHs);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("historicalmine/update")
    @RequiresPermissions("historicalmine:update")
    @ResponseBody
    public DataResult update(@RequestBody SpottableHistoricalmineNewEntity spottableHistoricalmine) {
        SpottableHistoricalmineNewService.updateById(spottableHistoricalmine);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("historicalmine/listByPage")
    @RequiresPermissions("historicalmine:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody SpottableHistoricalmineNewEntity spottableHistoricalmine) {
        Page page = new Page(spottableHistoricalmine.getPage(), spottableHistoricalmine.getLimit());
        LambdaQueryWrapper<SpottableHistoricalmineNewEntity> queryWrapper = SpottableHistoricalmineNewService.searchByTBBH(spottableHistoricalmine);
        IPage<SpottableHistoricalmineNewEntity> iPage = SpottableHistoricalmineNewService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }
}
